
proc ::dccore::HookCommand {sock cmd script {prio 50.0}} {
	variable $sock
	upvar 0 $sock state

	if {![info exists state(hookid)]} { set state(hookid) -1 }

	set hookid hook,$cmd,[incr state(hookid)]
	set state($hookid) $script
	set state(hooks) [lsort -real -index 1 \
		[lsort -unique [lappend state(hooks) [list $hookid $prio]]]]

	set hookid
}

proc ::dccore::RunHooks {sock cmd arglist} {
	variable $sock
	upvar 0 $sock state

	if {![info exists state(hooks)]} return

	foreach hook $state(hooks) {
		lassign $hook hookid prio
		set script [string map [list \
			%%    % \
			%A    [list $arglist] \
			%S    [list $sock] \
			%C    [list $cmd] \
			%P    [list $prio] \
		] $state($hookid)]
		set res [eval $script]
	}
}

